from setting_floor import sele_setting;
import time;
from selenium.webdriver.common.by import By;
import pytest;
from logs_floor import logs_file;
import allure;

'''
封装自动化用例方法核心:

1. 执行登录，让登录信息存储到浏览器中并返回；

2. 在用例方法中编写业务代码；

3. 对业务代码产生的结果进行断言；

4. 关闭浏览器；

'''

logs_pro = logs_file.get_log_pro();

@allure.epic("悦享速达")
@allure.feature("登录模块")
@pytest.mark.parametrize("case_name,username,userpwd,assert_content",[("登录功能-正例","悦享速达","123456","index"),("登录功能-用户名错误(反例)","悦享速达11","123456","login"),
                                             ("登录功能-密码错误(反例)","悦享速达","123456789","login"),("登录功能-用户名和密码错误(反例)","悦享速达12","1234561212","login")])
def test_login(case_name,username,userpwd,assert_content):
    allure.dynamic.title(case_name)
    browser_obj = sele_setting.get_browser("chrome");

    browser_obj.get("https://anmo.fangqiuchuanmei.com/admin/login");

    time.sleep(3);

    browser_obj.find_element(by=By.XPATH,value='/html/body/div/section/main/div/div[2]/form/div[1]/div/div/div/input').send_keys(username);

    time.sleep(3);

    browser_obj.find_element(by=By.XPATH,value='/html/body/div/section/main/div/div[2]/form/div[2]/div/div/div/input').send_keys(userpwd);

    time.sleep(3)

    browser_obj.find_element(by=By.XPATH,value='/html/body/div/section/main/div/div[2]/form/div[3]/div/button').click();

    time.sleep(5);

    if assert_content in browser_obj.current_url:

        print(case_name,"执行成功");

        logs_pro.info(case_name+"执行成功");

        assert True;


    else:

        print(case_name,"执行失败");

        logs_pro.error(case_name+"执行失败");

        assert False;

    browser_obj.quit();


@allure.epic("悦享速达")
@allure.feature("主页模块")
@allure.title("主页跳转验证")
def test_click_main():

    login_browser = sele_setting.true_login();
    time.sleep(5)
    login_browser.find_element(by=By.XPATH,value="/html/body/div/div/div[2]/div[3]/div/div/div[1]").click();

    time.sleep(5)
    if "welcome" in login_browser.current_url:

        print("主页跳转成功!");
        logs_pro.info("主页跳转成功!");

    else:

        print("主页跳转失败!");
        logs_pro.error("主页跳转失败!");

    login_browser.quit();










